package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.my.bean.ImageCodeBean;
import com.hxd.otc.module.my.contract.BindEmailContract;
import com.hxd.otc.module.my.model.UserModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

public class BindEmailPresenter extends BasePresenter<BindEmailContract.IView> implements BindEmailContract.IPresenter {

    private final UserModel mUserModel;

    public BindEmailPresenter(BindEmailContract.IView iView) {
        super(iView);
        mUserModel = UserModel.getInstance();
    }

    @Override
    public void sendEmailCode(String mail,  String sessionId) {
        mUserModel.getEmailCode(new BaseObserver<ImageCodeBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ImageCodeBean imageCodeBean) {
                mView.getEmailCodeSuccess(imageCodeBean);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<ImageCodeBean>>bindAutoDispose(), mail, "binder", "Android", "register", sessionId);

    }

    @Override
    public void bindEmail(final String email, String verCode) {
        mUserModel.bindEmail(email, verCode, new BaseObserver<String>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.bindEmailSuccess(email);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        },mView.<BaseBean<String>>bindAutoDispose());
    }
}
